home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1991: Code Warrior / bincue / Code Warrior.bin / Tools & Apps (Moof!) / OS⁄Toolbox / HyperMenus / NewMenu.c < prev    next >
Encoding:
Text File  |  1990-07-23  |  1.3 KB  |  93 lines  |  [TEXT/MPS ]

  1. //
  2. //        © Copyright 1990 Apple Computer, Inc.   By Ricardo Batista
  3. //
  4.  
  5. #include "Types.h"
  6. #include "Memory.h"
  7. #include "Menus.h"
  8. #include "Packages.h"
  9. #include "HyperXCMD.h"
  10.  
  11.  
  12. void GetHShort(Handle H, short *s);
  13. Handle SetHLong(long num);
  14. void GetHString(Handle H, char *s);
  15.  
  16. pascal void MAIN(XCmdPtr xcmd)
  17. {
  18.     char title[256];
  19.     short id;
  20.     long num;
  21.     
  22.     if (xcmd->paramCount != 2)
  23.         return;
  24.     GetHShort(xcmd->params[0], &id);
  25.     GetHString(xcmd->params[1], title);
  26.     num = (long) NewMenu(id, title);
  27.     xcmd->returnValue = SetHLong(num);
  28. }
  29.  
  30.  
  31. void GetHShort(Handle H, short *s)
  32. {
  33.     short len;
  34.     char st[256];
  35.     long num;
  36.     
  37.     *s = 0;
  38.     HLock(H);
  39.     len = (short) GetHandleSize(H);
  40.     if (len > 255)
  41.         len = 255;
  42.     BlockMove(*H, &st[1], (long) len);
  43.     HUnlock(H);
  44.     len = 1;
  45.     while (st[len])
  46.         len++;
  47.     st[0] = len - 1;
  48.     StringToNum(st, &num);
  49.     *s = (short) num;
  50. }
  51.  
  52.  
  53.  
  54. Handle SetHLong(long num)
  55. {
  56.     Handle H;
  57.     char st[60];
  58.     short len;
  59.     
  60.     NumToString(num, st);
  61.     len = st[0];
  62.     H = NewHandle((long) len);
  63.     if (H) {
  64.         HLock(H);
  65.         BlockMove(&st[1], *H, (long) len);
  66.         (*H)[len] = 0;
  67.     }
  68.     return(H);
  69. }
  70.  
  71.  
  72.  
  73.     
  74.  
  75.  
  76.  
  77. void GetHString(Handle H, char *s)
  78. {
  79.     short len;
  80.     char st[256];
  81.     
  82.     HLock(H);
  83.     len = (short) GetHandleSize(H);
  84.     if (len > 255)
  85.         len = 255;
  86.     BlockMove(*H, &st[1], (long) len);
  87.     HUnlock(H);
  88.     len = 1;
  89.     while (st[len])
  90.         len++;
  91.     st[0] = len - 1;
  92.     BlockMove(st, s, (long) len);
  93. }